import request from './request'
import type { ApiResponse } from './types'

// KPI数据类型
export interface KPIData {
  id: number
  name: string
  type: 'performance' | 'behavior' | 'ability'
  weight: number
  description: string
  standard: string
  department: string
  departmentIds: number[]
  createTime?: string
  updateTime?: string
}

// KPI分页查询参数
export interface KPIPageParams {
  current: number
  size: number
  name?: string
  type?: string
  departmentId?: number
}

// KPI分页响应数据
export interface KPIPageResponse {
  records: KPIData[]
  total: number
  size: number
  current: number
}

// 获取KPI列表
export const getKPIList = () => {
  return request<ApiResponse<KPIData[]>>({
    url: '/kpis/list',
    method: 'post',
    data: {}
  })
}

// 获取KPI分页列表
export const getKPIPage = (params: KPIPageParams) => {
  return request<ApiResponse<KPIPageResponse>>({
    url: '/kpis/page',
    method: 'post',
    data: params
  })
}

// 新增KPI
export const addKPI = (kpi: Omit<KPIData, 'id' | 'createTime' | 'updateTime'>) => {
  return request<ApiResponse<number>>({
    url: '/kpis/add',
    method: 'post',
    data: kpi
  })
}

// 编辑KPI
export const updateKPI = (kpi: KPIData) => {
  return request<ApiResponse<boolean>>({
    url: '/kpis/update',
    method: 'post',
    data: kpi
  })
}

// 删除KPI
export const deleteKPI = (id: number) => {
  return request<ApiResponse<boolean>>({
    url: '/kpis/delete',
    method: 'post',
    data: { id }
  })
}

// 获取KPI详情
export const getKPIDetail = (id: number) => {
  return request<ApiResponse<KPIData>>({
    url: '/kpis/detail',
    method: 'post',
    data: { id }
  })
}